﻿/***********************
*
* Author:彭承龙
* 介绍：Access数据库【业务逻辑层自动生成】
* 生成时间:2010年06月23日 01:23
*
************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using Util;
namespace Bussiness.zn
{
    /// <summary>
    /// 业务逻辑类UserInfoB
    /// </summary>
    public class UserInfoB
    {
        /// <summary>
        /// 添加一个UserInfo记录
        /// </summary>
        /// <Decription>此代码由CodeGenerate自动生成，作者：彭承龙</Decription>
        /// <param name="tb"></param>
        /// <returns></returns>
        public static Result Add(Model.zn.UserInfo tb)
        {
            OleDbConnection sqlCon = new OleDbConnection(Util.OleDbHelper.ConnectionString);
            sqlCon.Open();
            Result rs = new Result();
            OleDbTransaction SqlTran = sqlCon.BeginTransaction();
            try
            {
                rs = DBAccess.zn.UserInfoD.Add(SqlTran, tb);
                if (rs.IsSuccess)
                {
                    SqlTran.Commit();
                }
                else
                {
                    SqlTran.Rollback();
                }
            }
            catch (Exception ex)
            {
                SqlTran.Rollback();
                rs.Msg = ex.Message;
                throw ex;
            }
            finally
            {
                if (sqlCon.State == System.Data.ConnectionState.Open)
                {
                    sqlCon.Close();
                }
                SqlTran.Dispose();
                sqlCon.Dispose();
            }
            return rs;
        }
        /// <summary>
        /// 更新一个UserInfo记录
        /// </summary>
        /// <Decription>此代码由CodeGenerate自动生成，作者：彭承龙</Decription>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public static Result Update(Model.zn.UserInfo userInfo)
        {
            OleDbConnection sqlCon = new OleDbConnection(Util.OleDbHelper.ConnectionString);
            sqlCon.Open();
            Result rs = new Result();
            OleDbTransaction SqlTran = sqlCon.BeginTransaction();
            try
            {
                rs = DBAccess.zn.UserInfoD.Update(SqlTran, userInfo);
                if (rs.IsSuccess)
                {
                    SqlTran.Commit();
                }
                else
                {
                    SqlTran.Rollback();
                }
            }
            catch (Exception ex)
            {
                SqlTran.Rollback();
                rs.Msg = ex.Message;
                throw ex;
            }
            finally
            {
                if (sqlCon.State == System.Data.ConnectionState.Open)
                {
                    sqlCon.Close();
                }
                SqlTran.Dispose();
                sqlCon.Dispose();
            }
            return rs;
        }
        /// <summary>
        /// 根据Id删除一条记录
        /// </summary>
        /// <Decription>此代码由CodeGenerate自动生成，作者：彭承龙</Decription>
        /// <param name="userInfo.Id"></param>
        /// <returns></returns>
        public static Result Delete(int Id)
        {
            OleDbConnection sqlCon = new OleDbConnection(Util.OleDbHelper.ConnectionString);
            sqlCon.Open();
            OleDbTransaction SqlTran = sqlCon.BeginTransaction();
            Result rs = new Result();
            try
            {
                rs = DBAccess.zn.UserInfoD.Delete(SqlTran, Id);
                if (rs.IsSuccess)
                {
                    SqlTran.Commit();
                }
                else
                {
                    SqlTran.Rollback();
                }
            }
            catch (Exception ex)
            {
                SqlTran.Rollback();
                rs.Msg = ex.Message;
                throw ex;
            }
            finally
            {
                if (sqlCon.State == System.Data.ConnectionState.Open)
                {
                    sqlCon.Close();
                }
                SqlTran.Dispose();
                sqlCon.Dispose();
            }
            return rs;
        }
        /// <summary>
        /// 根据Id获取一个UserInfo实体
        /// </summary>
        /// <Decription>此代码由CodeGenerate自动生成，作者：彭承龙</Decription>
        /// <param name="UserInfo.Id"></param>
        /// <returns></returns>
        public static Model.zn.UserInfo GetModel(int id)
        {
            OleDbConnection sqlCon = new OleDbConnection(Util.OleDbHelper.ConnectionString);
            try
            {
                sqlCon.Open();
                Model.zn.UserInfo m_UserInfo = DBAccess.zn.UserInfoD.GetModel(sqlCon, id);
                sqlCon.Close();
                return m_UserInfo;
            }
            catch (Exception ex)
            {
                sqlCon.Close();
                throw ex;
            }
            finally
            {
                if (sqlCon.State == ConnectionState.Open) sqlCon.Close();
                sqlCon.Dispose();
            }
        }
        /// <summary>
        /// 通过条件返回对象UserInfo列表
        /// </summary>
        /// <Decription>此代码由CodeGenerate自动生成，作者：彭承龙</Decription>
        /// <param name="strWhere">查询条件</param>
        /// <returns>返回UserInfo数组</returns>
        public static Model.zn.UserInfo[] GetModels(string strWhere)
        {
            Model.zn.UserInfo[] m_UserInfos = null;
            Result rs = new Result();
            OleDbConnection conn = new OleDbConnection(Util.OleDbHelper.ConnectionString);
            conn.Open();
            try
            {
                m_UserInfos = DBAccess.zn.UserInfoD.GetModels(conn, strWhere);
                rs.IsSuccess = true;
            }
            catch (Exception e)
            {
                rs.Msg = e.Message;
                rs.IsSuccess = false;
                throw e;
            }
            finally
            {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Dispose();
            }
            return m_UserInfos;
        }


        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <Decription>此代码由CodeGenerate自动生成，作者：彭承龙</Decription>
        /// <param name="pageSize">每页的数</param>
        /// <param name="index">当前页</param>
        /// <returns></returns>
        public static Result GetDataSet(int pageSize, int index)
        {
            Result rs=new Result();
            OleDbConnection sqlCon = new OleDbConnection(Util.OleDbHelper.ConnectionString);
             try
            {                
                sqlCon.Open();
                rs= DBAccess.zn.UserInfoD.GetDataSet(sqlCon, pageSize, index);
                sqlCon.Close();               
            }
            catch (Exception ex)
            {
                rs.Msg =ex.Message;
                rs.IsSuccess = false;
                throw ex;
            }
            finally
            {
                if (sqlCon.State == ConnectionState.Open)
                {
                    sqlCon.Close();
                }
                sqlCon.Dispose();
            }
            return rs;
        }

        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <Decription>此代码由CodeGenerate自动生成，作者：彭承龙</Decription>
        /// <param name="pageSize">每页的数</param>
        /// <param name="index">当前页</param>
        /// <returns></returns>
        public static Result GetDataSet(int pageSize, int index,string strWhere,string orderBy,bool isDesc)
        {
            Result rs=new Result();
            OleDbConnection sqlCon = new OleDbConnection(Util.OleDbHelper.ConnectionString);

            try
            {
                sqlCon.Open();
                rs = DBAccess.zn.UserInfoD.GetDataSet(sqlCon, pageSize, index,strWhere,orderBy,isDesc);
                sqlCon.Close();
            }
            catch (Exception ex)
            {
                rs.Msg = ex.Message;
                rs.IsSuccess = false;
                throw ex;
            }
            finally
            {
                if (sqlCon.State == ConnectionState.Open)
                {
                    sqlCon.Close();
                }
                sqlCon.Dispose();
            }
            return rs;
        }
    }
}
